<?php
require_once 'Library/SA/Loader.php';
require_once 'Library/SA/Constants.php';
spl_autoload_register('SA_Loader::Autoload');
SA_Loader::addDir(realpath('library'));
if(isset($_POST['GmailID'])) {
    $userId = $_POST['GmailID'];
    $userpsw = $_POST['GmailPassword'];
    $is_loged = TRUE;
} else
    $is_loged = FALSE;
?>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <link href="grid.css" rel="stylesheet" type="text/css" />
        <title></title>
    </head>
    <body>
        <div class="container">
            <div class="span-6 prepend-16 last">
                <div class="span-6 last">
                    <form action="index.php" method="POST">
                        <div class="span-6 last">
                            <fieldset>
                                <legend>Google app login</legend>
                                <label for="GmailID">Gmail account</label>
                                <input type="text" id="GmailID" name="GmailID" value="<?php if($is_loged)
    echo $userId; ?>"/><br/>
                                <label for="GmailPassword">Gmail password</label>
                                <input type="password" id="GmailPassword" name="GmailPassword" value="<?php if($is_loged)
                                           echo $userpsw; ?>"/><br/>
                                <input type="submit" title="Login" value='login'>
                            </fieldset>
                        </div>
                        <div class="span-6 last">
                            <?php
                            if($is_loged) {
                                $google = new SA_Google_Autentification($userId, $userpsw, SA_Google_Autentification::SA_Documents_List_Data_API);
                                $result = $google->login();

                                if(!$result)
                                    echo '<div class=" error">' . $google->getError() . '</div>';
                                else
                                    echo '<div class=" success"> <b>You are login!</b></div>';
                            }
                            ?>
                        </div>
                    </form>
                </div>
            </div>
        </div>
        <?php
// put your code here
        ?>
    </body>
</html>
